<%--
    Document   : index
    Created on : Mar 17, 2010, 7:21:26 PM
    Author     : rmatos
--%>

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html >
    <head >
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>How to...</title>
        <link rel="stylesheet" type="text/css" href="resources/CoolWater.css"/>

    </head>

    <body>
        <div id="wrap">

            <c:import url="Header.jsp"/>

            <!-- content-wrap starts here -->
            <div id="content-wrap">

                <div id="main">

                    <h2>Classes</h2>

                    <h2>TblQuote.java</h2>

                    <h3>Code Example</h3>
                    <p><code>

                            @Entity<br />
                            @Table(name = "tbl_quote")<br />
                            @NamedNativeQueries({<br />
                            <br />
                            ...<br />
                            <br />
                            <br />
                            @NamedQuery(name = "TblQuote.findAll", query = "SELECT t FROM TblQuote t"),<br />
                            @NamedQuery(name = "TblQuote.findById", query = "SELECT t FROM TblQuote t WHERE t.id = :id"),<br />
                            @NamedQuery(name = "TblQuote.findByName", query = "SELECT t FROM TblQuote t WHERE t.name = :name"),<br />


                        </code></p>
                    <p class="post-footer align-left">
                        <a href="resources/code/classes/TblQuote.java" class="readmore">Read more</a>
                    </p>


                    <h2>SearchServlet.java</h2>
                    <h3>Code Example</h3>
                    <p><code>

                            String person = request.getParameter("person");<br />
                            List<String> quotes = em.createNamedQuery("TblQuote.findAllQuoteByName").setParameter("name", person).getResultList();<br />
                                <br />
                                request.setAttribute("personQuotes", quotes);<br />
                                request.setAttribute("person", person);<br />
                                <br />
                                RequestDispatcher dispatcher = request.getRequestDispatcher("SearchPerson.jsp");<br />
                                dispatcher.forward(request, response);<br />

                        </code></p>
                    <p class="post-footer align-left">
                        <a href="resources/code/classes/SearchServlet.java" class="readmore">Read more</a>
                    </p>

                    <h2>RandomServlet.java</h2>
                    <h3>Code Example</h3>
                    <p><code>
                            List<TblQuote> quotes = em.createNamedQuery("TblQuote.findAll").getResultList();<br />
                                int selectedIndex = r.nextInt(quotes.size());<br />
                                <br />
                                request.setAttribute("quote", quotes.get(selectedIndex));<br />
                                <br />
                                RequestDispatcher dispatcher =  request.getRequestDispatcher("RandomQuote.jsp");<br />
                                dispatcher.forward(request, response);<br />

                        </code></p>
                    <p class="post-footer align-left">
                        <a href="resources/code/classes/RandomServlet.java" class="readmore">Read more</a> |
                    </p>

                    <h2>QuoteContextListener.java</h2>
                    <h3>Code Example</h3>
                    <p><code>

                            EntityManagerFactory emf = Persistence.createEntityManagerFactory("QuotesPU");<br />
                            EntityManager em = emf.createEntityManager();<br />

                            //Index's ComboBox Items<br />
                            List<String> names = em.createNamedQuery("TblQuote.findAllName").getResultList();<br />

                                sce.getServletContext().setAttribute("names", names);<br />

                        </code></p>
                    <p class="post-footer align-left">
                        <a href="resources/code/classes/QuoteContextListener.java" class="readmore">Read more</a> |
                    </p>



                    <h2>Web Pages and JavaScript</h2>
                    <table>
                        <tr>
                            <th>Page's Name</th>
                            <th>link</th>
                            <th>description</th>
                        </tr>
                        <tr>
                            <td>Index</td>
                            <td><a href="resources/code/pages/index.txt">Index.jsp</a></td>
                            <td>Main page</td>

                        </tr>


                        <tr>
                            <td>Header</td>
                            <td><a href="resources/code/pages/Header.txt">Header.jsp</a></td>
                            <td>Header of the page</td>

                        </tr>

                        <tr>
                            <td>Footer</td>
                            <td><a href="resources/code/pages/Footer.txt">Footer.jsp</a></td>
                            <td>Footer of the page</td>

                        </tr>

                        <tr>
                            <td>How</td>
                            <td><a href="resources/code/pages/How.txt">How.jsp</a></td>
                            <td>How did you do that? page</td>

                        </tr>

                        <tr>
                            <td>RandomQuote</td>
                            <td><a href="resources/code/pages/RandomQuote.txt">RandomQuote.jsp</a></td>
                            <td>Show the info of the picked(random) quote</td>

                        </tr>

                        <tr>
                            <td>ListQuotes</td>
                            <td><a href="resources/code/pages/ListQuotes.txt">ListQuotes.jsp</a></td>
                            <td>Show the components to execute a search</td>

                        </tr>

                        <tr>
                            <td>SearchPerson</td>
                            <td><a href="resources/code/pages/SearchPerson.txt">SearchPerson.jsp</a></td>
                            <td>Show the quotes of selected person</td>

                        </tr>

                        <tr>
                            <td>quotes_functions</td>
                            <td><a href="resources/code/quotes_functions.txt">quotes_functions.js</a></td>
                            <td>Some of the basic functions of the page</td>

                        </tr>


                    </table>



                </div>


                <div id="sidebar">

                    <img src="resources/registeryourquote.jpg" width="174" height="190" alt="register"/>
                    <center><h2>Register your Quotes</h2></center>
                </div>

            </div>




            <c:import url="Footer.jsp"/>

        </div>



    </body>
</html>
